# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=hcloud
pkgver=1.48.0
pkgrel=0
pkgdesc="Command-line interface for Hetzner Cloud"
url="https://github.com/hetznercloud/cli"
license="MIT"
arch="all"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/hetznercloud/cli/archive/v$pkgver/hcloud-$pkgver.tar.gz"
builddir="$srcdir/cli-$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build \
		-trimpath \
		-ldflags "\
			-X github.com/hetznercloud/cli/internal/version.Version=$pkgver \
			-X github.com/hetznercloud/cli/internal/version.versionPrerelease= \
			" \
		-v \
		./cmd/hcloud

	./hcloud completion bash > $pkgname.bash
	./hcloud completion fish > $pkgname.fish
	./hcloud completion zsh > $pkgname.zsh
}

check() {
	go test ./...
}

package() {
	install -Dm755 hcloud -t "$pkgdir"/usr/bin/

	install -Dm644 $pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish "$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish
	install -Dm644 $pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
a5684872a00303b95f77df92b29936e0b53a3eb7da2a34ce3777f8013db90e26432cafbaaffd75f33094157369ffd017f51bcdec2de2dc32b9293f7e8ec15135  hcloud-1.48.0.tar.gz
"
